home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Developer Essentials / DTS Sample Code / Snippets / Platforms & Tools / MacApp / PICTDialog / UDialogs.cp < prev    next >
Encoding:
Text File  |  1992-01-01  |  2.9 KB  |  98 lines  |  [TEXT/MPS ]

  1. // Copyright © 1991 Apple Computer, Inc. All rights reserved.
  2. //    Example of a modal dialog with a PICT inside, with some additional
  3. // TEditText control.
  4. // Kent Sandvik DTS
  5.  
  6. #include "UDialogs.h"
  7.  
  8. extern "C" char* memcpy(void*, void*, int);
  9. #define pstrcpy(p,q)  memcpy(p, q, q[0]+1)    // added for translation: Pascal strcpy
  10.  
  11. const long    kFileType        =    'MOOF';
  12. const short    kModalID           =    3000;
  13. const short    cName                =    4000;
  14. const short kMoof                =     9999;
  15.  
  16. //============================================================================
  17. #pragma segment AInit
  18.  
  19. pascal void TDialogsApplication::IDialogsApplication()
  20. {
  21.     this->IApplication(kFileType);
  22.  
  23.     if (gDeadStripSuppression){                // get a needed TPicture object
  24.         TPicture* aPicture = new TPicture;
  25.     }
  26. }
  27.  
  28.  
  29. //----------------------------------------------------------------------------
  30. pascal void TDialogsApplication::HandleFinderRequest()
  31. {
  32.     // we don't handle Finder requests
  33. }
  34.  
  35.  
  36. //------------------------------------------------------------------------------
  37. #pragma segment ASelCommand
  38. pascal TCommand * TDialogsApplication::DoMenuCommand(CmdNumber aCmdNumber)
  39. {
  40.     switch (aCmdNumber){
  41.     
  42.         case cName:
  43.                 this->ShowModalDialog();        // show dialog box
  44.                 return gNoChanges;                //    return dummy command object; not Undoable
  45.                 
  46.         default:                                        //    always do this, so other objects get a chance
  47.             return inherited::DoMenuCommand(aCmdNumber);
  48.  
  49.     }
  50. }
  51.  
  52.  
  53. //------------------------------------------------------------------------------
  54. #pragma segment ARes
  55. pascal void TDialogsApplication::DoSetupMenus()
  56. {
  57.     inherited::DoSetupMenus();        //    always do this, so other objects get chance
  58.     Enable(cName, true);
  59. }
  60.  
  61.  
  62. //------------------------------------------------------------------------------
  63. #pragma segment ASelCommand
  64. pascal void TDialogsApplication::ShowModalDialog()
  65. {
  66.     const IDType kDialogView    = 'dlog';    //    dialog view identifier
  67.     const IDType kName            = 'name';    //    edit text identifier
  68.     const IDType kOK                = 'okok';    //    OK button identifier
  69.     const IDType kCancel            = 'cncl';    //    Cancel button identifier
  70.     const IDType kPict            = 'pic1';    // PICT view
  71.     
  72.     Str255        userName;
  73.     
  74.     TWindow *aWindow = NewTemplateWindow(kModalID, NULL);
  75.     TDialogView *aDialogView = (TDialogView *) aWindow->FindSubView(kDialogView);
  76.     TEditText     *anEditText = (TEditText *) aWindow->FindSubView(kName);
  77.     TPicture     *aPicture = (TPicture *) aWindow->FindSubView(kPict);
  78.  
  79.     
  80.     PicHandle aHandle = GetPicture(kMoof);                // get PICT 
  81.     aPicture->SetPicture(aHandle,TRUE);                    // draw it into the window
  82.     
  83.     IDType dismisser = aDialogView->PoseModally();    // show the modal dialog
  84.  
  85. #if qDebug
  86.     if (dismisser == kOK) {
  87.         anEditText->GetText(userName);
  88.         printf("The user typed %P in the box\n", userName);
  89.         };
  90.     if (dismisser == kCancel)
  91.         printf("The user cancelled the box\n");
  92. #endif    
  93.  
  94.     aWindow->Close();                                        //    dispose of the dialog window
  95. }
  96.  
  97.  
  98. // THE END ---------------------------------------------------------------------